package com.shed.demo.service.impl;

import java.util.List;

import com.shed.demo.dao.MenuDao;
import com.shed.demo.domain.Menu;
import com.shed.demo.service.MenuService;

public class MenuServiceImpl implements MenuService {
	private MenuDao MenuDao;

	public void setMenuDao(MenuDao MenuDao) {
		this.MenuDao = MenuDao;
	}

	public void createMenu(Menu menu) {
		MenuDao.create(menu);
	}

	public void deleteMenu(Long menuID) {
		MenuDao.remove(MenuDao.get(menuID));
	}

	@SuppressWarnings("unchecked")
	public List<Menu> getChildrenByUpID(Long menuUpID) {
		return (List<Menu>) MenuDao.find("from Menu where menuUpID = " + menuUpID + " order by menuSort desc");
	}

	public void updateMenu(Menu menu) {
		MenuDao.update(menu);
	}

	public Menu getMenuByMenuID(Long menuCode) {
		return MenuDao.get(menuCode);
	}
}
